package com.lin.filegraph.utils.parser.node;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.EnumDeclaration;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:24
 */

public class JEnumNode extends JTypeNode {

    public JEnumNode(String filePath, ASTNode astNode, String className, String modifier, String strOuterType,
                     List<String> listStrSuperInterface) {
        super(filePath, astNode, className, modifier, strOuterType, listStrSuperInterface);
    }

    public List<JEnumConstantNode> getAllEnumConstants() {
        List<JEnumConstantNode> listEnumConstant = new ArrayList<JEnumConstantNode>();
        List<? extends JTreeNode> tempList = super.getChildrenNodeList();
        for (JTreeNode basedNode : tempList) {
            if (basedNode instanceof JEnumConstantNode) {
                JEnumConstantNode enumConstantNode = (JEnumConstantNode) basedNode;
                listEnumConstant.add(enumConstantNode);
            }
        }
        return listEnumConstant;
    }

    public EnumDeclaration getEnumDeclaration() {
        ASTNode astNode = getAstNode();
        if (astNode instanceof EnumDeclaration) {
            return (EnumDeclaration) astNode;
        }
        return null;
    }

    @Override
    public String toString() {
        return "[EnumNode] " + getTypeName() + "  StartLine: " + getStartLine();
    }

    @Override
    public void displayStrInheritance() {
        // TODO Auto-generated method stub
        if (!getListStrSuperInterface().isEmpty()) {
            System.out.println(this);
            if (!getListStrSuperInterface().isEmpty()) {
                System.out.println("    StrImplementedInterfaces:" + getListStrSuperInterface());
            }
        }
    }
}

